package com.ray.service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceConfigurationError;

import org.apache.xmlbeans.impl.xb.xsdschema.NarrowMaxMin;
import org.quartz.impl.jdbcjobstore.AttributeRestoringConnectionInvocationHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.stereotype.Service;
/**
 * 财务模块中的入库结算service
* <p>Title: WarehouseInSumMoneyService</p>  
* <p>Description: </p>  
* @author 李斌  
* @date 2018年5月23日
 */
import org.springframework.util.Assert;

import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterSynonymStatement;
import com.google.appengine.repackaged.com.google.api.client.util.Data;
import com.ray.bean.AttendanceMonthSummaryBean;
import com.ray.bean.DatatablesViewPageBean;
import com.ray.bean.OrderCustomTagBean;
import com.ray.bean.PutOutOrderBean;
import com.ray.bean.PutOutWarehouseBean;
import com.ray.bean.ReceiptPaymentRecordBean;
import com.ray.bean.UserBean;
import com.ray.bean.WarehouseInOutDetailBean;
import com.ray.bean.WarehouseInSumMoneyBean;
import com.ray.bean.ReceiptPaymentRecordBean.ReceivePaymentDetailRecord;
import com.ray.exception.ServiceException;
import com.ray.mapper.CompanyMaterialMapper;
import com.ray.mapper.DingTalkMapper;
import com.ray.mapper.OrderMapper;
import com.ray.mapper.WarehouseInSumMoneyMapper;
import com.ray.pojo.MyUser;
import com.ray.pojo.ShowEquipmentPojo;
import com.ray.pojo.WarehouseInOutSumMoneyPojo;
import com.ray.util.CreateIdUtil;
import com.ray.util.ReturnStringUtil;
import com.ray.util.StringUtil;
import com.ray.util.TimeAndUnix;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.thoughtworks.xstream.mapper.Mapper.Null;

import net.sf.json.JSONArray;
@Service
public class WarehouseInSumMoneyService {
	
	@Autowired
	private WarehouseInSumMoneyMapper warehouseInSumMoneyMapper;
	@Autowired
	DingTalkMapper dingTalkMapper;
	@Autowired
	OrderMapper orderMapper;
	@Autowired
	CompanyMaterialMapper companyMaterialMapper;
	@Autowired
	ApprovalService approvalService;
	@Autowired
	CompanyMaterialCountService companyMaterialCountService;
	@Autowired
	EquipmentService equipmentService;
	@Autowired
	AttendanceService attendanceService;
	@Autowired
	WorkshopService workshopService;
	@Autowired
	PutOutServiceNew putOutServiceNew;
	/**
	 * 获取仓库入库结算数据（采购单入库与无采购单入库数据）
	 * @param map
	 * @return
	 */
	public DatatablesViewPageBean<WarehouseInSumMoneyBean> getWarehouseInSumMoneyDetail(Map<String,Object> map){
		DatatablesViewPageBean<WarehouseInSumMoneyBean> datatablesViewPageBean = new DatatablesViewPageBean<WarehouseInSumMoneyBean>();
		int count = warehouseInSumMoneyMapper.getWarehouseInSumMoneyDetailCount(map);
		datatablesViewPageBean.setiTotalDisplayRecords(count);
		datatablesViewPageBean.setiTotalRecords(count);
		List<WarehouseInSumMoneyBean> warehouseInSumMoneyBeans = warehouseInSumMoneyMapper.getWarehouseInSumMoneyDetail(map);
		datatablesViewPageBean.setReturnData(warehouseInSumMoneyBeans);
		return datatablesViewPageBean; 
	}
	
	/**
	 * 获取仓库出库（出库给客户）结算数据
	 * @param map
	 * @return
	 */
	public DatatablesViewPageBean<WarehouseInSumMoneyBean> getWarehouseOutBalanceData(Map<String,Object> map){
		DatatablesViewPageBean<WarehouseInSumMoneyBean> datatablesViewPageBean = new DatatablesViewPageBean<WarehouseInSumMoneyBean>();
		int count = warehouseInSumMoneyMapper.getWarehouseOutBalanceDataCount(map);
		datatablesViewPageBean.setiTotalDisplayRecords(count);
		datatablesViewPageBean.setiTotalRecords(count);
		List<WarehouseInSumMoneyBean> warehouseInSumMoneyBeans = warehouseInSumMoneyMapper.getWarehouseOutBalanceData(map);
		datatablesViewPageBean.setReturnData(warehouseInSumMoneyBeans);
		return datatablesViewPageBean; 
	}
	
	
	
	/**
	 * 修改入库结算状态(是否结算)
	* @date 2018年5月25日 上午9:11:22 
	* @author 李斌
	* @return void 
	* @throws
	 */
	public boolean setIsBalanceByWarehouseInSumId(Map<String, Object> map) {
		double receiptPaymentPrice=0;
		int type=0;
		String id ="";
		List<ReceiptPaymentRecordBean>  payList=warehouseInSumMoneyMapper.getReceiptPaymentRecordByInOutId(map.get("id").toString(),"0");
		Assert.isTrue(null==payList || payList.size()<=0,"该记录有收付款未审核不可结算");
		String receviePaymentUserName ="";
		//是外协结算
		if(null!=map.get("isPutOut") && "1".equals(map.get("isPutOut"))) {
			Map putOutMap=new HashMap();
			List<String> typeIdList = new ArrayList<String>();
			typeIdList.add(map.get("id").toString());
			putOutMap.put("loginCompany", map.get("loginCompany"));
			putOutMap.put("typeIdList", typeIdList);
			List<PutOutOrderBean> putOutList=putOutServiceNew.getPutoutOrderNoPage(putOutMap);
			Assert.isTrue(null!=putOutList && putOutList.size()>0,"该外协记录不存在");
			PutOutOrderBean putOutWarehouseBean = putOutList.get(0);
			receviePaymentUserName = putOutWarehouseBean.getSupplierName();
			Assert.isTrue(1!=putOutWarehouseBean.getIsBalance(),"该记录已结算，不可操作");
			receiptPaymentPrice=putOutWarehouseBean.getReceiptPaymentPrice();
			id=putOutWarehouseBean.getTypeId();
		}else {
			WarehouseInSumMoneyBean inOutRecord=warehouseInSumMoneyMapper.getInOutRecordById(map);
			Assert.isTrue(null!=inOutRecord,"该出入库记录不存在");
			Assert.isTrue(!"1".equals(inOutRecord.getIsBalance()),"该记录已结算，不可操作");
			receiptPaymentPrice= inOutRecord.getReceiptPaymentPrice();
			type = Integer.parseInt(inOutRecord.getType());
			receviePaymentUserName = inOutRecord.getProviderName();
			id=inOutRecord.getId();
		}
		//如果没有收付款直接结算
		if(0==receiptPaymentPrice) {
			this.notPayAutobalance(map,type,"手动点击结算",receviePaymentUserName,id);
		}else {//如果有收付款了，结算金额为收付款金额
			map.put("money", receiptPaymentPrice);
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		map.put("balanceTime", simpleDateFormat.format(new Date()));
		map.put("balanceUser", map.get("loginUserId"));
		int row = 0;
		if(null!=map.get("isPutOut") && "1".equals(map.get("isPutOut"))) {
			row =  warehouseInSumMoneyMapper.setPutOutIsBalanceByWarehouseInSumId(map);
		}else {
			row =  warehouseInSumMoneyMapper.setIsBalanceByWarehouseInSumId(map);
		}
		if(row>0) {
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 未付款直接结算
	 * @param map
	 * @param type
	 * @param mode
	 * @param receviePaymentUserName
	 * @param inOutId
	 */
	public  void notPayAutobalance(Map<String, Object> map, int type,String mode,String receviePaymentUserName,String inOutId) {
		Map payMap=new HashMap();
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String dateStr=simpleDateFormat.format(new Date());
		ReceiptPaymentRecordBean receiptPaymentRecordBean= new ReceiptPaymentRecordBean();
		int souce = map.get("isPutOut")==null?0:Integer.parseInt(map.get("isPutOut").toString());
		//如果是出库，则为收款
		double money=Double.parseDouble(map.get("money").toString());
		if(9==type) {
			payMap.put("id", dingTalkMapper.getApprovalNo(CreateIdUtil.RECEIPT));
			receiptPaymentRecordBean.setType(1);
		}else {//否则为付款
			payMap.put("id", dingTalkMapper.getApprovalNo(CreateIdUtil.PAYMENT));
			receiptPaymentRecordBean.setType(2);
		}
		receiptPaymentRecordBean.setSumMoney(money);
		receiptPaymentRecordBean.setReceiptPaymentMode(mode);
		receiptPaymentRecordBean.setCustomerName(receviePaymentUserName);
		receiptPaymentRecordBean.setSource(souce);
		payMap.put("loginUserId", map.get("loginUserId"));
		payMap.put("status", 1);
		payMap.put("loginCompany", map.get("loginCompany"));
		payMap.put("approvalUser", map.get("loginUserId"));
		payMap.put("approvalTime", dateStr);
		List<ReceivePaymentDetailRecord> detailList = new ArrayList<ReceivePaymentDetailRecord>();
		ReceivePaymentDetailRecord detailRecord= new ReceivePaymentDetailRecord();
		detailRecord.setId(StringUtil.getUUID());
		detailRecord.setInOutId(inOutId);
		detailRecord.setPrice(money);
		detailRecord.setSource(souce);
		detailList.add(detailRecord);
		receiptPaymentRecordBean.setDetailList(detailList);
		payMap.put("data", receiptPaymentRecordBean);
		int row=warehouseInSumMoneyMapper.saveReceiptPaymentRecord(payMap);
		Assert.isTrue(row>0,ReturnStringUtil.SAVE_ERROR);
//		int updateRow=warehouseInSumMoneyMapper.updateReceiptPaymentPrice(payMap);
//		Assert.isTrue(updateRow>0,ReturnStringUtil.UPDATE_ERROR); 
	}

	/**
	 * 获取入库结算汇总金额
	* @date 2018年5月31日 上午9:40:35 
	* @author 李斌
	* @return Map<String,Object>  
	* @throws
	 */
	public Map getSumMoneyByWarehouseSum(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getSumMoneyByWarehouseSumOrder(map);
	}

	/**
	 * 获取公司仓库制单人
	 * @param map
	 * @return
	 */
	public List<MyUser> getWarehouseUserList(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getWarehouseUserList(map);
	}

	/**
	 * 获取出库结算总额
	 * @param map
	 * @return
	 */
	public Map getWarehouseOutBalanceSumMoney(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getWarehouseOutBalanceSumMoney(map);
	}
	
	/**
	 * 获取出库财务汇总
	 * @param map
	 * @return
	 */
	public List<Map> getWarehouseOutBalanceSum(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getWarehouseOutBalanceSum(map);
	}

	/**
	 * 获取公司收付款方式
	 * @param map
	 * @return
	 */
	public List<String> getPaymentModeList(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getPaymentModeList(map);
	}

	/**
	 * 保存收付款记录
	 * inOutId 出入库id
	 * type 类型  1 收款  2 付款
	 * price 金额
	 * receiptPaymentMode 收付款方式
	 * payType 操作方式 1只生成记录  2 生成记录并审核
	 * @author nate 
	 */
	public void saveReceiptPaymentRecord(Map map) {
		StringUtil.checkIsTrue(map, "inOutId", "未获取到出入库id");
		StringUtil.checkIsTrue(map, "type", "未获取到出收付款类型");
		StringUtil.checkIsTrue(map, "price", "未获取到收付款金额");
		StringUtil.checkNotNull(map, "receiptPaymentMode", "未获取到收付款方式");
		StringUtil.checkIsTrue(map, "payType", "未获取到操作方式");
		WarehouseInSumMoneyBean inOutRecord=null;
		//验证是否已结算
		//是外协收付款
		if(map.get("isPutOut") != null && "1".equals(map.get("isPutOut"))) {
			Map putOutMap=new HashMap();
			List<String> typeIdList = new ArrayList<String>();
			typeIdList.add(map.get("inOutId").toString());
			putOutMap.put("loginCompany", map.get("loginCompany"));
			putOutMap.put("typeIdList", typeIdList);
			List<PutOutOrderBean> putOutList=putOutServiceNew.getPutoutOrderNoPage(putOutMap);
			Assert.isTrue(null!=putOutList && putOutList.size()>0,"该外协记录不存在");
			PutOutOrderBean putOutWarehouseBean = putOutList.get(0);
			Assert.isTrue(1!=putOutWarehouseBean.getIsBalance(),"该记录已结算，不可操作");
		}else {
			Map inOutMap=new HashMap<>();
			inOutMap.put("id", map.get("inOutId"));
			inOutRecord=warehouseInSumMoneyMapper.getInOutRecordById(inOutMap);
			Assert.isTrue(null!=inOutRecord,"该出入库记录不存在");
			Assert.isTrue(!"1".equals(inOutRecord.getIsBalance()),"该记录已结算，不可操作");
		}
		int type =Integer.parseInt(map.get("type").toString());//收付款类型
		int payType=Integer.parseInt(map.get("payType").toString());//操作类型
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String dateStr=simpleDateFormat.format(new Date());
		map.put("createUser", map.get("loginUserId"));
		map.put("createTime", dateStr);
		//如果是收款
		if(1==type) {
			map.put("id", dingTalkMapper.getApprovalNo(CreateIdUtil.RECEIPT));
		}else {//付款
			map.put("id", dingTalkMapper.getApprovalNo(CreateIdUtil.PAYMENT));
		}
		//如果是只生成记录
		if(1==payType) {
			map.put("status", 0);
		}else {//如果是生成记录并审核
			map.put("status", 1);
			map.put("approvalUser", map.get("loginUserId"));
			map.put("approvalTime", dateStr);
			//更新出入库已收付金额
			int updateRow = 0;
			if(map.get("isPutOut") != null && "1".equals(map.get("isPutOut"))) {
				updateRow=warehouseInSumMoneyMapper.updatePutOutReceiptPaymentPrice(map);
			}else {
				//如果是分期付款，查看本次应付金额有没有达到
				updateRow=warehouseInSumMoneyMapper.updateReceiptPaymentPrice(map);
			}
			Assert.isTrue(updateRow>0,ReturnStringUtil.OPERATION_ERROR);
		}
		Assert.isTrue(false,"作废");
//		int row=warehouseInSumMoneyMapper.saveReceiptPaymentRecord(map);
//		Assert.isTrue(row>0,ReturnStringUtil.OPERATION_ERROR);
	}


	/**
	 * 审核收付款记录
	 * id 出入库id
	 * status 状态 1通过 2 不通过
	 * @author nate 
	 */
	public void approvalReceiptPaymentRecord(Map<String, Object> map) {
		StringUtil.checkIsTrue(map, "id", "未获取到id");
		StringUtil.checkIsTrue(map, "status", "未获取到状态");
		int status=Integer.parseInt(map.get("status").toString());
		map.remove("status");
		List<ReceiptPaymentRecordBean> list=warehouseInSumMoneyMapper.getReceiptPaymentRecord(map);
		Assert.isTrue(list !=null && list.size()>0,"该记录不存在");
		ReceiptPaymentRecordBean receiptPaymentRecordBean=list.get(0);
		Assert.isTrue(receiptPaymentRecordBean.getStatus()==0,"该记录已审核，不可操作");
		if(1==status) {
//			map.put("price", receiptPaymentRecordBean.getPrice());
//			map.put("inOutId", receiptPaymentRecordBean.getInOutId());
			int updateRow = 0 ;
			//如果是外协
			if(receiptPaymentRecordBean.getSource()==1) {
				updateRow=warehouseInSumMoneyMapper.updatePutOutReceiptPaymentPrice(map);
			}else {
				//更新出入库已收付金额
				updateRow=warehouseInSumMoneyMapper.updateReceiptPaymentPrice(map);
			}
			Assert.isTrue(updateRow>0,ReturnStringUtil.UPDATE_ERROR);
		}
		map.put("status", status);
		int row=warehouseInSumMoneyMapper.approvalReceiptPaymentRecord(map);
		Assert.isTrue(row>0,ReturnStringUtil.OPERATION_ERROR);
	}
	
	
	/**
	 * 通过id获取出入库记录
	 * inOutId 出入库id
	 * @param map
	 * @return
	 */
	public List<ReceiptPaymentRecordBean> getReceiptPaymentRecordByInOutId(Map map) {
		StringUtil.checkIsTrue(map, "inOutId", "未获取到出入库id");
		return warehouseInSumMoneyMapper.getReceiptPaymentRecordByInOutId(map.get("inOutId").toString(), "");
	}

	
	/**
	 * 获取收付款记录
	 * startTime 开始时间
	 * endTime 结束时间
	 * type 类型  1 收款  2 付款
	 * receiptPaymentMode 收付款方式
	 * createUser 经手人
	 * start 分页参数
	 * length 分页参数
	 * isSum 是否求和  传任意值则求和，不传或未''则不求和(点击分页和刷新列表时不需求和)
	 * status 状态  0 未审核 1 已审核 2 已退回
	 * @author nate 
	 */
	public Map<String,Object> getReceiptPaymentRecord(Map<String, Object> map) {
		Map<String,Object> returnMap=new HashMap<String,Object>();
		DatatablesViewPageBean<ReceiptPaymentRecordBean> datatablesViewPageBean=new DatatablesViewPageBean<ReceiptPaymentRecordBean>();
        Map approvalMap=new HashMap();
        approvalMap.put("type", "11");
        approvalMap.put("loginUserId", map.get("loginUserId"));
        approvalMap.put("loginCompany", map.get("loginCompany"));
		List<String> canApprovalUserId=approvalService.getApprovalIdByLoginId(approvalMap);
		List<ReceiptPaymentRecordBean> returnList=warehouseInSumMoneyMapper.getReceiptPaymentRecord(map);
		for(ReceiptPaymentRecordBean rr:returnList) {
			if(canApprovalUserId.contains(rr.getCreateUser())) {
				rr.setIsCanApproval(1);
			}else {
				rr.setIsCanApproval(2);
			}
		}
		int count =warehouseInSumMoneyMapper.getReceiptPaymentRecordCount(map);
		datatablesViewPageBean.setReturnData(returnList);
		datatablesViewPageBean.setiTotalDisplayRecords(count);
		datatablesViewPageBean.setiTotalRecords(count);
		returnMap.put("pageData", datatablesViewPageBean);//分页数据
		
		//如果需要查询总和
		if(null!=map.get("isSum") && !"".equals(map.get("isSum"))) {
			/**
			 * 求和  值为map appReceiptSum(已审收款总额)  notAppReceiptSum(待审收款总额) 
			 *            appPaymentSum(已审付款总额) notAppPaymentSum(待审付款总额)
			 */
			returnMap.put("sumData", warehouseInSumMoneyMapper.getReceiptPaymentRecordSum(map));
		}
		
		return returnMap;
	}

	/**
	 * 获取收付款经手人
	 * @param map
	 * @return
	 */
	public List<MyUser> getReceiptPaymentRecordUser(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getReceiptPaymentRecordUser(map);
	}

	/**
	 * id id 
	 * 删除收付款记录
	 * @param map
	 */
	public void deleteReceiptPaymentRecord(Map<String, Object> map) {
		StringUtil.checkIsTrue(map, "id", "未获取到id");
		List<ReceiptPaymentRecordBean> list=warehouseInSumMoneyMapper.getReceiptPaymentRecord(map);
		Assert.isTrue(null!=list && list.size()>0,"该记录已删除");
		ReceiptPaymentRecordBean rrBean=list.get(0);
		Assert.isTrue(rrBean.getStatus()!=1,"该记录已审核不可删除");
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String dateStr=simpleDateFormat.format(new Date());
		map.put("date", dateStr);
		int row=warehouseInSumMoneyMapper.deleteReceiptPaymentRecord(map);
		Assert.isTrue(row>0,ReturnStringUtil.DELETE_ERROR);
	}

	/**
	 * 修改收付款记录
	 * id  id
	 * price 金额
	 * @param map
	 */
	public void updateReceiptPaymentRecord(Map<String, Object> map) {
		StringUtil.checkIsTrue(map, "id", "未获取到id");
		StringUtil.checkIsTrue(map, "price", "未获取到价格");
		List<ReceiptPaymentRecordBean> list=warehouseInSumMoneyMapper.getReceiptPaymentRecord(map);
		Assert.isTrue(null!=list && list.size()>0,"该记录已删除");
		ReceiptPaymentRecordBean rrBean=list.get(0);
		Assert.isTrue(rrBean.getStatus()!=1,"该记录已审核不可修改");
		int row=warehouseInSumMoneyMapper.updateReceiptPaymentRecord(map);
		Assert.isTrue(row>0,ReturnStringUtil.UPDATE_ERROR);
	}

	/**
	 * 获取单个出入库收付款详情（付款已审数量，未审数量）
	 * @param map
	 * @return
	 */
	public List<Map> getOneWarehousePayMentDetail(Map map) {
		StringUtil.checkIsTrue(map, "idArray", "未获取到出入库id");
		String idArray = map.get("idArray").toString();
		JSONArray jsonArray = JSONArray.fromObject(idArray);
		List<String> idList = jsonArray.subList(0, jsonArray.size());
		Assert.isTrue(idList.size()>0,"未获取到出入库id");
		map.put("idList", idList);
		return warehouseInSumMoneyMapper.getOneWarehousePayMentDetail(map);
	}

	/**
	 * 获取财务报表数据
	 * @param map
	 * @return
	 */
	public Map  getFinancialStatements(Map map) {
		Map paramMap=new HashMap();
		paramMap.put("loginCompany", map.get("loginCompany"));
		//应收总额
		paramMap.put("isBalance", 0);//未结算
		Map  shouMap=this.getWarehouseOutBalanceSumMoney(paramMap);
		shouMap=shouMap==null?new HashMap():shouMap;
		//应付总额
		Map  fuMap =this.getSumMoneyByWarehouseSum(paramMap);
		fuMap=fuMap==null?new HashMap():fuMap;
		paramMap.remove("isBalance");
		//获取未付工资
		Double salary=this.getNotPaySalary(paramMap);
		//仓库原料汇总
		paramMap.put("isValid", 1);//有库存
		paramMap.put("isFinance", 1);//是财务
		Double warehousePrice=companyMaterialCountService.getCompanyMaterialCountPrice(paramMap);
		warehousePrice=warehousePrice==null?0.0:warehousePrice;
		paramMap.remove("isValid");
		paramMap.remove("isFinance");
		//成品仓价格汇总
		Double finishPrice=warehouseInSumMoneyMapper.getFinishPrice(paramMap);
		finishPrice=finishPrice==null?0.0:finishPrice;
		//获取设备价格
		Map machineMap=this.getMachinePrice(paramMap);
		//车间原料统计
		Double workShopPrice=workshopService.getWorkShopMaterialSumPrice(paramMap);
	    //车间领走物料价格
		Double personReceive=warehouseInSumMoneyMapper.getPersonReceivePrice(paramMap);
		Map returnMap=new HashMap();
		returnMap.put("yingShouZhangKuan", Double.parseDouble(shouMap.get("sum")==null?"0":shouMap.get("sum").toString())-Double.parseDouble(shouMap.get("receiptPaymentPrice")==null?"0":shouMap.get("receiptPaymentPrice").toString()));
		returnMap.put("cunHuo",finishPrice+warehousePrice);
		returnMap.put("gunDingZiCan",machineMap.get("machineSumPrice"));
		returnMap.put("leiJiXheJiu",machineMap.get("machineDepreciationSumPrice"));
		returnMap.put("cheJinZaiZhi",workShopPrice);
		returnMap.put("yuanGongLingLiao",personReceive);
		returnMap.put("yingFuZhangKuan", Double.parseDouble(fuMap.get("sum")==null?"0":fuMap.get("sum").toString())-Double.parseDouble(fuMap.get("receiptPaymentPrice")==null?"0":fuMap.get("receiptPaymentPrice").toString()));
		returnMap.put("yingFuGongZi", salary);
		return returnMap;
	}

	/** 
	 * 获取设备金额信息
	 * @param paramMap
	 * @return
	 */
	private Map getMachinePrice(Map paramMap) {
		List<ShowEquipmentPojo> allEqList=equipmentService.getAllShowEquipmentPojo(paramMap);
		Double sumPrice=allEqList.stream().mapToDouble(ShowEquipmentPojo::getPurchasePrice).sum();
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String toDay=simpleDateFormat.format(new Date());
		Double depreciationPrice=0.0;
		for(int i=0;i<allEqList.size() ; i++) {
			ShowEquipmentPojo o=allEqList.get(0);
			int aleradyUserDay=0;//已使用天数
			int allUserDat=0;//可使用天数
			try {
				aleradyUserDay=TimeAndUnix.getDateDays(o.getPurchaseTime(), toDay);
				allUserDat=TimeAndUnix.getDateDays(o.getPurchaseTime(), o.getDepreciableLife());
				allUserDat=allUserDat==0?1:allUserDat;
			} catch (Exception e) {
				aleradyUserDay=0;
				allUserDat=1;
			}
			depreciationPrice =depreciationPrice + o.getPurchasePrice() * aleradyUserDay/allUserDat;
		}
		Map returnMap=new HashMap();
		returnMap.put("machineSumPrice", sumPrice);
		returnMap.put("machineDepreciationSumPrice", depreciationPrice);
		return returnMap;
	}

	/**
	 * 获取本月和上月应付工资总额
	 * @param paramMap
	 * @return
	 * @throws ParseException 
	 */
	private Double getNotPaySalary(Map paramMap)  {
		Double returnValue=0.0;
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
		String toSay=simpleDateFormat.format(new Date());
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -1);
		cal.set(Calendar.DATE, 1);
		String  lastMonthOneDay=simpleDateFormat.format(cal.getTime());//上个月1号
		paramMap.put("startDate", lastMonthOneDay);
		paramMap.put("endDate", toSay);
		try {
			DatatablesViewPageBean<AttendanceMonthSummaryBean> datatablesViewPageBean=attendanceService.getMonthSummaryByDeptAndWorkshop(paramMap);
		    List<AttendanceMonthSummaryBean> detailList=datatablesViewPageBean.getReturnData();
		    returnValue=detailList.stream().mapToDouble(AttendanceMonthSummaryBean::getRealSalary).sum();
		} catch (Exception e) {
			returnValue=0.0;
		}
		paramMap.remove("startDate");
		paramMap.remove("endDate");
		return returnValue;
	}

	/**
	 * 获取应付款汇总
	 * @param map
	 * @return
	 */
	public List<Map> getAccountPayableSum(Map<String, Object> map) {
		return warehouseInSumMoneyMapper.getAccountPayableSum(map);
	}

}
